/**
 * IBtreeTable.java
 * Copyright (C) 2011 Yuanyan<yuanyan.cao@gmail.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * For information on how to redistribute this software under
 * the terms of a license other than GNU General Public License
 * contact yuanyan.cao@gmail.com
 */
package edu.rabbit.kernel.table;


import edu.rabbit.DbEncoding;
import edu.rabbit.DbException;
import edu.rabbit.ValueType;
import edu.rabbit.kernel.memory.IMemoryPointer;

/**
 * Interface of table over B-Tree.
 * 
 * @author Yuanyan<yanyan.cao@gmail.com>
 * 
 * 
 */
public interface IBtreeTable {

    /**
     * Close B-Tree table cursor.
     * 
     * @throws DbException
     */
    void close() throws DbException;

    /**
     * Lock B-Tree table cursor's mutex.
     * 
     * @throws DbException
     */
    void lock() throws DbException;

    /**
     * Unlock B-Tree table cursror's mutex.
     */
    void unlock();

    /**
     * Check of end of B-Tree table cursor.
     * 
     * @return true if there is not more records.
     * @throws DbException
     */
    boolean eof() throws DbException;

    /**
     * Go to first record.
     * 
     * @return true if there is at least one record.
     * @throws DbException
     */
    boolean first() throws DbException;

    /**
     * Go to last record.
     * 
     * @return true if there is at least one record.
     * @throws DbException
     */
    boolean last() throws DbException;

    /**
     * Go to next record.
     * 
     * @return true if there is at least one record and end of cursor is not
     *         reached yet
     * @throws DbException
     */
    boolean next() throws DbException;

    /**
     * Go to previous record.
     * 
     * @return true if there is at least one record and begin of cursor is not
     *         reached yet
     * @throws DbException
     */
    boolean previous() throws DbException;

    /**
     * @return
     * @throws DbException
     */
    IBtreeRecord getRecord() throws DbException;

    /**
     * @param write
     */
    void lockTable(boolean write);

    /**
     * @return
     * @throws DbException
     */
    DbEncoding getEncoding() throws DbException;

    /**
     * Get count of fields in current record.
     * 
     * @return count of fields
     * @throws DbException
     */
    int getFieldsCount() throws DbException;

    /**
     * Get type of field.
     * 
     * @param field
     *            number of field begin from zero
     * @return type of field
     * @throws DbException
     */
    ValueType getFieldType(int field) throws DbException;

    /**
     * Check to field has null value.
     * 
     * @param field
     *            number of field begin from zero
     * @return true if field value is null
     * @throws DbException
     */
    boolean isNull(int field) throws DbException;

    /**
     * Get field's value as string.
     * 
     * @param field
     *            number of field begin from zero
     * @return field's value as string
     * @throws DbException
     */
    String getString(int field) throws DbException;

    /**
     * Get field's value as integer.
     * 
     * @param field
     *            number of field begin from zero
     * @return field's value as integer
     * @throws DbException
     */
    long getInteger(int field) throws DbException;

    /**
     * Get field's value as real (float).
     * 
     * @param field
     *            number of field begin from zero
     * @return field's value as real
     * @throws DbException
     */
    double getFloat(int field) throws DbException;

    /**
     * Get field's value as BLOB.
     * 
     * @param field
     *            number of field begin from zero
     * @return field's value as BLOB
     * @throws DbException
     */
    IMemoryPointer getBlob(int field) throws DbException;

    /**
     * Get values as objects.
     * 
     * @return
     * @throws DbException
     */
    Object[] getValues() throws DbException;

    /**
     * Get value as object.
     * 
     * @param field
     * @return
     * @throws DbException
     */
    Object getValue(int field) throws DbException;

    /**
     * Returns true if cursor has been moved. Side effect of this is restore
     * position of cursor.
     * 
     * @return
     * @throws DbException
     */
    boolean hasMoved() throws DbException;

    /**
     * @throws DbException
     */
    void clear() throws DbException;

    /**
     * @throws DbException
     */
    void delete() throws DbException;

}
